<?php

use common\enums\AccountTypeEnum;
use yii\helpers\Html;
use yii\grid\GridView;

use common\helpers\ImageHelper;
use common\helpers\Url;
use common\models\member\Member;
use common\models\member\BankAccount;
use common\models\member\MemberWithdraw;

$this->title = '提现管理';
$this->params['breadcrumbs'][] = ['label' => $this->title];

?>

<div class="row">
    <div class="col-xs-12">
        <div class="box">
            <div class="box-header">
                <h3 class="box-title"><?= $this->title; ?></h3>
                <div class="box-tools">

                </div>
            </div>
            <!-- &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<?php echo  Html::tag('button', '批量导出', ['class' => 'btn btn-info btn-sm  export']) ?> -->
            <div class="box-body table-responsive">
                <?= GridView::widget([
                    'dataProvider' => $dataProvider,
                    // 'filterModel' => $searchModel,
                    //重新定义分页样式
                    'tableOptions' => ['class' => 'table table-hover'],
                    'options' => ['class' => 'order-view', 'style' => 'overflow:auto', 'id' => 'orders'],

                    'columns' => [
                        [
                            'class' => 'yii\grid\SerialColumn',
                            'visible' => true, // 不显示#
                        ],
                        // [
                        //     'class'=>\yii\grid\CheckboxColumn::className(),
                        //     'checkboxOptions' => function ($model, $key, $index, $column) {
                        //          return ['value'=>$model->id,'class'=>'checkbox'];
                        //     },
                        // ],
                        [
                            'attribute' => 'id',
                            'headerOptions' => ['class' => 'col-md-1'],
                        ],
                        'order_no',
                        
                        [
                            'attribute' => 'member_id',
                            'label' => '会员信息',
                            'value' => function ($model) {
                                return  '会员编号:' . $model->member->username . '<br>' .
                                    '真实姓名:' . $model->member->realname . '<br>' ;
                            },
                            'format' => 'raw',
                        ],
                        [
                            'attribute' => 'type',
                            'value' => function ($model) {
                                return AccountTypeEnum::html($model->type);
                            },
                            'filter' => false,
                            'format' => 'raw',
                        ],
                        'card_number',
                        'amount',
                        'fee',
                        'money',
                        'created_at:datetime',
                        'confirm_at:datetime',
                        [
                            'header' => '收款二维码',
                            'value' => function ($model) {
                                return $model->pay_img ? ImageHelper::fancyBox(Html::encode($model->pay_img)) : '未上传';
                            },
                            'filter' => false,
                            'format' => 'raw',
                        ],
                        'note',
                        [
                            'attribute' => '操作',
                            'value' => function ($model) {
                                if ($model->status == 0) {
                                    $ser =  Html::a('锁定', ['suo', 'id' => $model->id, 'status' => 1], ['class' => 'btn btn-success btn-sm']);
                                } elseif ($model->status == 1) {
                                    $ser =  Html::a('取消锁定', ['suo', 'id' => $model->id, 'status' => 0], ['class' => 'btn btn-danger btn-sm']) . '   ' . Html::a('处理', ['view', 'id' => $model->id], ['class' => 'btn btn-success btn-sm',  'data-toggle' => 'modal', 'data-target' => '#ajaxModalLg',]);
                                } else {
                                    $ser = MemberWithdraw::setStates($model->status);
                                }
                                return $ser;
                            },
                            'headerOptions' => array(
                                'width' => '150',
                                'style' => 'text-align:center',
                            ),
                            'format' => 'raw'
                        ],
                    ]

                ]); ?>
            </div>
        </div>
    </div>
    <script type="text/javascript">
        //导出订单
        $(".export").on("click", function() {

            var state = 1;
            // var start_time = $('#w1-start').val();
            // var end_time =  $('#w1-end').val();
            var str = '';
            if (window.location.search.substring(1)) {
                str = window.location.search.substring(1);
            } else {
                str = "status=" + state;
            }
            // window.open("order-export?id="+keys+"&status="+status+"&start_time="+start_time+"&end_time="+end_time);
            window.open("order-export?" + str);

        });
    </script>